from flask import Flask
from project.App.views.view import user
from project.App.views.route_param_view import route_param_blue
from project.App.views.request_view import request_blue
from project.App.views.response_view import response_blue
from project.App.views.redirect import redirect_blue
from project.App.views.cookie import cookie_blue
from project.App.views.session import session_blue
from project.App.views.template import template_blue
from project.App.views.template_parent import template_parent_blue
from .exts import init_exts


def crate_app():
    app = Flask(__name__)
    # 注册蓝图
    app.register_blueprint(blueprint=user)
    app.register_blueprint(blueprint=route_param_blue)
    app.register_blueprint(blueprint=request_blue)
    app.register_blueprint(blueprint=response_blue)
    app.register_blueprint(blueprint=redirect_blue)
    app.register_blueprint(blueprint=cookie_blue)
    app.register_blueprint(blueprint=session_blue)
    app.register_blueprint(blueprint=template_blue)
    app.register_blueprint(blueprint=template_parent_blue)
   # print(app.config)
    # 设置secret的key
    app.config["SECRET_KEY"] = "abc1245"

    # 设置数据库的连接 sqllite安装 不需要密码和用户名
    DB_URL = "sqlite:///sqlite3.db"
    app.config["SQLALCHEMY_DATABASE_URI"] = DB_URL  # 配置连接数据库路径的地址
    app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False  # 禁止对象追踪修改
    # 初始化插件
    init_exts(app)

    # <Config
    # {'DEBUG': False, 'TESTING': False,
    # 'PROPAGATE_EXCEPTIONS': None, 'SECRET_KEY': None,
    # 'PERMANENT_SESSION_LIFETIME': datetime.timedelta(days=31),
    # 'USE_X_SENDFILE': False, 'SERVER_NAME': None, 'APPLICATION_ROOT': '/', 'SESSION_COOKIE_NAME': 'session',
    # 'SESSION_COOKIE_DOMAIN': None, 'SESSION_COOKIE_PATH': None, 'SESSION_COOKIE_HTTPONLY': True,
    # 'SESSION_COOKIE_SECURE': False, 'SESSION_COOKIE_SAMESITE': None, 'SESSION_REFRESH_EACH_REQUEST': True,
    # 'MAX_CONTENT_LENGTH': None, 'SEND_FILE_MAX_AGE_DEFAULT': None, 'TRAP_BAD_REQUEST_ERRORS': None,
    # 'TRAP_HTTP_EXCEPTIONS': False, 'EXPLAIN_TEMPLATE_LOADING': False, 'PREFERRED_URL_SCHEME': 'http',
    # 'TEMPLATES_AUTO_RELOAD': None, 'MAX_COOKIE_SIZE': 4093}>

    return app


# 启动入口
app = crate_app()
if __name__ == '__main__':
    app.run(debug=True)
